<div class="modal-dialog modal-lg" id="metaGenAttrs_M_Dialog">
  <div class="modal-content">
    <div class="modal-header modal-header-condensed">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">×</span></button>
      <h4 class="modal-title"><i class="fa  fa-object-group"></i>元对象[${entity.objName}(${entity.objComment})]属性管理</h4>
    </div>
    <div class="modal-body">
      <div class="box box-primary " >
        <div class="box-header">
          <h3 class="box-title">属性列表</h3>
          <div class="box-tools pull-right">
            <div class="btn-group" >
                <button type="button" class="btn  btn-success btn-sm" data-btntype="add">新增</button>
                <button type="button" class="btn  btn-warning btn-sm" data-btntype="edit" data-position="tool">修改</button>
                <button type="button" class="btn  btn-danger btn-sm" data-btntype="delete" data-position="tool">删除</button>
            </div>
          </div>
          <!-- /.box-tools -->
        </div>
         <!-- /.box-header -->
        <div class="box-body table-responsive  min-height-control-200" >
          <table class="table table-bordered table-condensed table-striped mytable " id="metaGenAttrTable"> 
          </table>
        </div>
        <!-- /.box-body -->
      </div>
      <!-- /.box -->
    </div>

    <!-- /.modal-body -->
  </div>
  <!-- /.modal-content -->
  <div class="modal fade" id="metaGenAttr_A_Model" data-reftableid="metaGenAttrTable"></div> 
  <div class="modal fade" id="metaGenAttr_E_Model" data-reftableid="metaGenAttrTable"></div>
</div>
<script>
  require([ "jquery", "bootbox","bootstrap", "bootstrapTable","bootstrapTab_CH","validate"],function($,bootbox) {
    var container = $("#metaGenAttrs_M_Dialog");
    container.triggerDelete = function(ids){
      $.ajax({
              type: "POST",
              url: "${contextPath}/metaGenAttr/delete",
              dataType:"json",
              async: false,
              contentType:"application/json",
              data:JSON.stringify(ids),
              //data:{ids},
              success: function(data){
                  if("success" == data.status){
                    frameworkOptions.showSuccessMessages(data.message); 
                    container.find('#metaGenAttrTable').bootstrapTable('refresh'); 
                    
                  }else if("failure" == data.status){
                    frameworkOptions.showErrorMessages(data.message);
                  }
              }
          }); 
    }
    container.triggerEditView = function(id){
      container.find("#metaGenAttr_E_Model").load('${contextPath}/metaGenAttr/g2Edit/'+id,{},
        function(responseTxt,statusTxt,xhr){
            if(statusTxt=="success"){
                container.find("#metaGenAttr_E_Model").modal({
                    backdrop:'static',
                    show:true
                });
            }  
            if(statusTxt=="error"){
              frameworkOptions.showInfoMessages(xhr);
            }     
        });
    }
    container.triggerAddView = function(id){
      container.find("#metaGenAttr_A_Model").load('${contextPath}/metaGenAttr/g2Add?objId='+id,{},
        function(responseTxt,statusTxt,xhr){
            if(statusTxt=="success"){
                container.find("#metaGenAttr_A_Model").modal({
                    backdrop:false,
                    show:true
                });
            }  
            if(statusTxt=="error"){
              frameworkOptions.showInfoMessages(xhr);
            }     
        });
    }  
    container.find('#metaGenAttrTable').bootstrapTable(
      {
        url : "${contextPath}/metaGenAttr/queryObjAttrs",
        dataType : "json",
        pagination : false, //分页
        dataField : 'data.rows',
        noToolBar : true,//新增 是否不显示原生的工具栏 
        customPagination : true,//新增 是否启用自定义分页
        customPaginationTitleSelector : "#prt_metaGenAttrPage", //新增 客户分页统计信息容器的JQUERY选择器
        customPaginationListSelector : "#prl_metaGenAttrPage", //新增 客户分页条的JQUERY选择器 
        queryParams : function(params) {
          return {
            pageSize :(params.limit || 15),
            pageNum : (params.offset || 1),
            objId:${entity.id}
          }
        },
        onPostBody :function(){
          //表体载入DOM后触发
          container.find("[data-toggle='tooltip']").tooltip();
               
        },
        singleSelect : false,
        //search : true, //显示搜索框
        sidePagination : "client", //服务端处理分页
        columns : [
            {
              field : 'id',
              align : 'center',
              width : 30,
              title : '<label class="mylabel"></label>',
              formatter : function(value,row, index) {
                var checkbox = '<label class="mylabel" id="'+value+'"></label>';
                return checkbox;
              }
            },

            {
              title : '名称',
              field : 'attrName',
              align : 'left',
              valign : 'middle'
            },
            {
              title : '备注',
              field : 'attrComment',
              align : 'left',
              valign : 'middle',
            },
            {
              title : '详情',
              field : 'attrName',
              align : 'left',
              formatter : function(value,row, index) {
                var d = '';
                if(row.relationShip == '1:N' || row.relationShip == 'N:N' ){
                    d +=(row.relationType || 'List') +"< <span class='label label-default tooltopcss' data-placement='top' data-toggle='tooltip' title='"+row.attrType+"'>"+row.attrShortTypeName+"</span>> "+value +" ;";
                }else{
                    d +=" <span class='label label-default tooltopcss' data-placement='top'  data-toggle='tooltip' title='"+row.attrType+"'>"+row.attrShortTypeName+"</span> "+value +" ;";
                }
                return d;
              }
            },
            {
              title : '操作',
              field : 'id',
              width : 120,
              align : 'center',
              formatter : function(value,row, index) {
                var d = '<a href="#" data-btntype="edit" data-position="row" data-rowid="'+row.id+'"><span  class="badge bg-yellow"><i class="fa  fa-edit" >编辑</i></span></a><a href="#" data-btntype="delete" data-position="row" data-rowid="'+row.id+'"><span  class="badge bg-red"><i class="fa  fa-remove" >删除</i></span> </a>';
                return d;
              }
            } ]
    });
    container.on('click','[data-btntype="edit"]',function(e){
        if($(e.currentTarget).data('position') == "row"){
          container.triggerEditView($(e.currentTarget).data('rowid'));
        }else{
          if(container.find('#metaGenAttrTable').bootstrapTable('getSelections').length==1){
            container.triggerEditView(container.find('#metaGenAttrTable').bootstrapTable('getSelections')[0].id);
          }else{
            frameworkOptions.showInfoMessages("请选择一条记录");
              
          }
        }
    });
    container.on('click','[data-btntype="delete"]',function(e){
        var ids = new Array();
        if($(e.currentTarget).data('position') == "row"){
          ids.push($(e.currentTarget).data('rowid'));
        }else{
          if(container.find('#metaGenAttrTable').bootstrapTable('getSelections').length>0){
            $.each(container.find('#metaGenAttrTable').bootstrapTable('getSelections'),function(index,obj){
              ids.push(obj.id);   
            });
          }else{
            frameworkOptions.showInfoMessages("请选择记录");
              
          }
        }
        if(ids && ids.length>0){
          bootbox.confirm({
                message: "你确定要删除该元属性吗?",
                buttons: {
                  confirm: {
                     label: "确定",
                     className: "btn-primary btn-sm",
                  },
                  cancel: {
                     label: "取消",
                     className: "btn-default btn-sm",
                  }
                },
                callback: function(result) {
                    if(result) {
                        container.triggerDelete(ids);
                    }
                }
            });
        }
    });

    
    //销毁调用container.find('.tooltopcss').tooltip('destroy');
    container.on('click','button[data-btntype="add"]',function(e){        
      container.triggerAddView(${entity.id});

    });
    
  });
</script>